﻿using System.Windows;
using System.Windows.Controls;
using System.Collections.Generic;

namespace SQLProviders.UI
{
    /// <summary>
    /// Interaction logic for ServerDetailsView.xaml
    /// </summary>
    public partial class ServerDetails : UserControl, SQPlugin.IServerDetails
    {
        /// <summary>
        /// Constructor for the server details Wizard page
        /// </summary>
        public ServerDetails()
        {
            InitializeComponent();

            // Hook up the DataContext so that databinding will work
            DataContext = this;
        }

        #region IServerDetails

        /// <summary>
        /// Return the server details entered into the Server Details user control
        /// </summary>
        /// <returns>A server object containing the connection details entered by the user</returns>
        public Models.Server GetServerDetails()
        {
            // Store connection details
            Dictionary<string, string> connectionDetails = new Dictionary<string, string>();
            connectionDetails.Add("UserName", UserName);
            connectionDetails.Add("Password", Password);
            connectionDetails.Add("WindowsAuthentication", WindowsAuthentication.ToString());

            // Create a server object and return it
            Models.Server server = new Models.Server(ServerName, ServerProvider.ServerID, connectionDetails);

            return server;
        }

        #endregion

        /// <summary>
        /// The name of the server we are getting databases for
        /// </summary>
        public string ServerName
        {
            get
            {
                return (string)GetValue(ServerNameProperty);
            }
            set
            {
                SetValue(ServerNameProperty, value);
            }
        }

        /// <summary>
        /// The user name to use when connecting to the server
        /// </summary>
        public string UserName
        {
            get
            {
                return (string)GetValue(UserNameProperty);
            }
            set
            {
                SetValue(UserNameProperty, value);
            }
        }

        /// <summary>
        /// The password to use when connecting to the server
        /// </summary>
        public string Password
        {
            get
            {
                return (string)GetValue(PasswordProperty);
            }
            set
            {
                SetValue(PasswordProperty, value);
            }
        }

        /// <summary>
        /// Whether or not to use Windows Authentication when connecting to the server
        /// </summary>
        public bool WindowsAuthentication
        {
            get
            {
                return (bool)GetValue(WindowsAuthenticationProperty);
            }
            set
            {
                SetValue(WindowsAuthenticationProperty, value);
            }
        }

        /// <summary>
        /// Using a DependencyProperty as the backing store for ServerName.  This enables animation, styling, binding, etc... 
        /// </summary>
        public static readonly DependencyProperty ServerNameProperty =
            DependencyProperty.Register("ServerName", typeof(string), typeof(ServerDetails), new UIPropertyMetadata(null));

        /// <summary>
        /// Using a DependencyProperty as the backing store for UserName.  This enables animation, styling, binding, etc... 
        /// </summary>
        public static readonly DependencyProperty UserNameProperty =
            DependencyProperty.Register("UserName", typeof(string), typeof(ServerDetails), new UIPropertyMetadata(null));

        /// <summary>
        /// Using a DependencyProperty as the backing store for Password.  This enables animation, styling, binding, etc... 
        /// </summary>
        public static readonly DependencyProperty PasswordProperty =
            DependencyProperty.Register("Password", typeof(string), typeof(ServerDetails), new UIPropertyMetadata(null));

        /// <summary>
        /// Using a DependencyProperty as the backing store for WindowsAuthentication.  This enables animation, styling, binding, etc... 
        /// </summary>
        public static readonly DependencyProperty WindowsAuthenticationProperty =
            DependencyProperty.Register("WindowsAuthentication", typeof(bool), typeof(ServerDetails), new UIPropertyMetadata(true));
    }
}
